package com.example.user.app;

import android.content.ContentResolver;
import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.net.Uri;
import android.provider.BaseColumns;

/**
 * Created by hzn on 14-6-26.
 */
public class Contacts implements BaseColumns {
    private Contacts() {}

    private static final String contentUri = "content://"
            + ContactsProvider.AUTHORITY + "/%s/contacts";

    public static Uri getContentUri(String username) {
        return Uri.parse(String.format(contentUri, username));
    }

    public static final String NAME = "name";
    public static final String MOBILE_NUMBER = "mobile_number";
    public static final String CREATE_AT = "create_at";

    private static final String[] DEFAULT_CONTACTS_PROJECT = new String[] {
            _ID,
            NAME,
            MOBILE_NUMBER,
            CREATE_AT
    };

    public static final int COLUMN_ID = 0;
    public static final int COLUMN_NAME = 1;
    public static final int COLUMN_MOBILE_NUMBER = 2;
    public static final int COLUMN_CREATE_AT = 3;

    public static boolean addContact(ContentResolver resolver,String username, ContentValues values) {
        Uri uri = getContentUri(username);
        values.put(CREATE_AT, System.currentTimeMillis());
        resolver.insert(uri, values);

        return true;
    }

    public static Cursor startQuery(ContentResolver resolver, String username) {
        return resolver.query(Contacts.getContentUri(username), DEFAULT_CONTACTS_PROJECT,
                null, null, null);
    }



}
